package com.geostar.constructionland.attachment.entity;

import java.io.Serializable;

/**
 * 
 * portal接口返回的result对象
 * 
 * @author wanqing
 * @version [版本号, 2016年8月4日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public class Result implements Serializable {

	private static final long serialVersionUID = 2376981387964656872L;
	private static final String UNKNOWN_MESSAGE = "未定义的提示信息";

	/* 所有成功的成功码都是0 */
	public static final String SUCCESS = "0";
	public static final String SUCCESS_MESSAGE = "成功";

	public static final String ERROR = "1";
	public static final String ERROR_MESSAGE = "失败";
	
	public static final String INVALID_PARAM = "2";
	public static final String INVALID_PARAM_MESSAGE = "无效的参数";
	
	
	
	/* 域用户登陆&退出错误码&错误信息BEGIN */
	public static final String LOGIN_AUTHENTICATION_FAILED = "1001";
	public static final String LOGIN_AUTHENTICATION_FAILED_MESSAGE = "身份验证失败";

	public static final String LOGIN_COMMUNICATION_FAILED = "1002";
	public static final String LOGIN_COMMUNICATION_FAILED_MESSAGE = "AD域连接失败";

	public static final String LOGIN_UNKNOWN_ERROR = "1003";
	public static final String LOGIN_UNKNOWN_ERROR_MESSAGE = "身份验证未知异常";

	public static final String LOGOUT_FAILED = "1051";
	public static final String LOGOUT_FAILED_MESSAGE = "退出失败";
	/* 域用户登陆&退出错误码&错误信息END */
	
	/* 数据源错误码&错误信息BEGIN */
	public static final String DS_NOT_EXIST = "2001";
	public static final String DS_NOT_EXIST_MESSAGE = "目标数据源不存在";
	
	public static final String DS_TEST_FAILED = "2002";
	public static final String DS_TEST_FAILED_MESSAGE = "数据源验证失败";
	
	public static final String DS_ADD_FAILED = "2101";
	public static final String DS_ADD_FAILED_MESSAGE = "数据源保存失败";

	public static final String DS_DEL_FAILED = "2201";
	public static final String DS_DEL_FAILED_MESSAGE = "数据源删除失败";

	public static final String DS_MOD_FAILED = "2301";
	public static final String DS_MOD_FAILED_MESSAGE = "数据源修改失败";

	public static final String DS_GET_FAILED = "2401";
	public static final String DS_GET_FAILED_MESSAGE = "数据源查询失败";
	/* 数据源错误码&错误信息END */

	private String code;
	private String message;

	public Result() {
		super();
	}

	public Result(String code) {
		this.code = code;
		this.message = getMessageByCode(code);
	}

	public Result(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	@Override
    public String toString() {
        return "Result [code=" + code + ", message=" + message + "]";
    }

    /**
	 * 根据信息码获取对应提示信息 <功能详细描述>
	 * 
	 * @param code
	 * @return [参数说明]
	 * 
	 * @return String [返回类型说明]
	 * @exception throws [违例类型] [违例说明]
	 * @see [类、类#方法、类#成员]
	 * @author Jimmy 创建时间: 2016年12月15日
	 */
	public static String getMessageByCode(String code) {
		if (code.equals(SUCCESS))
			return SUCCESS_MESSAGE;
		else if (code.equals(ERROR))
			return ERROR_MESSAGE;
		else if (code.equals(INVALID_PARAM))
		    return INVALID_PARAM_MESSAGE;
		/* 域用户登陆&退出错误码&错误信息BEGIN */
		else if (code.equals(LOGIN_AUTHENTICATION_FAILED))
			return LOGIN_AUTHENTICATION_FAILED_MESSAGE;
		else if (code.equals(LOGIN_COMMUNICATION_FAILED))
			return LOGIN_COMMUNICATION_FAILED_MESSAGE;
		else if (code.equals(LOGIN_UNKNOWN_ERROR))
			return LOGIN_UNKNOWN_ERROR_MESSAGE;
		else if (code.equals(LOGOUT_FAILED))
			return LOGOUT_FAILED_MESSAGE;
		/* 域用户登陆&退出错误码&错误信息END */
		/* 数据源错误码&错误信息BEGIN */
		else if (code.equals(DS_NOT_EXIST))
			return DS_NOT_EXIST_MESSAGE;
		else if (code.equals(DS_TEST_FAILED))
		    return DS_TEST_FAILED_MESSAGE;
		else if (code.equals(DS_ADD_FAILED))
			return DS_ADD_FAILED_MESSAGE;
		else if (code.equals(DS_DEL_FAILED))
			return DS_DEL_FAILED_MESSAGE;
		else if (code.equals(DS_MOD_FAILED))
			return DS_MOD_FAILED_MESSAGE;
		else if (code.equals(DS_GET_FAILED))
			return DS_GET_FAILED_MESSAGE;
		/* 数据源错误码&错误信息END */
		return UNKNOWN_MESSAGE;
	}

}
